package com.chinamoney.wppm.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.chinamoney.wppm.dao.BdmDao;
import com.chinamoney.wppm.entity.BudgetManagement;
import com.chinamoney.wppm.util.ResultMessage;

/**
 * 
 * @author Jason_Jiang
 *
 */
@Service
public class BdmService {
	
	@Autowired
	private BdmDao bdmDao;
	
	/**
	 * 获取部门的需求变更单花费
	 * @param id
	 * @return
	 */
	@Transactional(readOnly = true)
	public ResultMessage<?> getDemandChangeCost(String deptName) {
		String cost = "0";
		switch(deptName) {
		case "11e8-856a-ce14d7a9-8e09-d19654dcc6f2":
			cost = "615.51";
			break;
		case "11e8-736e-f0d5a4f0-9d86-eda4e5a8ac8d":
			cost = "41.27";
			break;
		case "11e8-9a10-98c1c595-8e20-a7fef31a94c3":
			cost = "58.97";
			break;
		case "11e8-7e9d-fbce8120-8e09-d19654dcc6f2":
			cost = "5.19";
			break;
		case "11e8-7045-efcbdf34-9d86-eda4e5a8ac8d":
			cost = "324.85";
			break;
		case "11e8-7385-dcc1c142-9d86-eda4e5a8ac8d":
			cost = "501.85";
			break;
		case "11e8-b4d4-d0b81019-9e60-a79adcd7e6c4":
			cost = "0";
			break;
		default : 
			break;
		}
		return ResultMessage.createSuccessResultMessage(cost);
	}
	
	/**
	 * 根绝ID获取部门预算
	 * @param id
	 * @return
	 */
	@Transactional(readOnly = true)
	public ResultMessage<?> getBdmById(String id) {
		BudgetManagement bdm = bdmDao.getBdmById(id);
		return ResultMessage.createSuccessResultMessage(bdm);
	}
	
	/**
	 *    按年度统计各部门的预算支出
	 * @param year：年度，格式是 year
	 * @return
	 */
	@Transactional(readOnly = true)
	public List<Map<String, Object>> getBdmInDeptByYear(@Param("year") String year) {
		return bdmDao.getBdmInDeptByYear(year+"-01-01 00:00:00");
	}
	
	/**
	 * 
	 * @param page
	 * @param rows
	 * @return
	 */
	@Transactional(readOnly = true)
	public ResultMessage<?> getBdms(int page, int rows) {
		Map<String, Object> result = new HashMap<>();
		List<BudgetManagement> eleForms = bdmDao.getBdms(page, rows);
		int total = bdmDao.getBdmsCount();
		result.put("total", total);
		result.put("data", eleForms);
		return ResultMessage.createSuccessResultMessage(result);
	}
	
	/**
	 * 
	 * @param title
	 * @return
	 */
	public Map<String, Object> getBdmByDept(String dept) {
		return bdmDao.getBdmByDept(dept);
	}

}
